/**
 * Copyright (c) 2013-Now http://dreamcode123321.com All rights reserved.
 */
package com.jeesite.modules.ab.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeesite.modules.sys.utils.UserUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.ab.entity.AbFeekback;
import com.jeesite.modules.ab.service.AbFeekbackService;

import java.util.Date;

/**
 * 服务反馈Controller
 * @author dc
 * @version 2020-08-15
 */
@Controller
@RequestMapping(value = "${adminPath}/ab/abFeekback")
public class AbFeekbackController extends BaseController {

	@Autowired
	private AbFeekbackService abFeekbackService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public AbFeekback get(String backCode, boolean isNewRecord) {
		return abFeekbackService.get(backCode, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequestMapping(value = {"list", ""})
	public String list(AbFeekback abFeekback, Model model) {
		model.addAttribute("abFeekback", abFeekback);
		return "modules/ab/abFeekbackList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("ab:abFeekback:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<AbFeekback> listData(AbFeekback abFeekback, HttpServletRequest request, HttpServletResponse response) {
		abFeekback.setPage(new Page<>(request, response));
		Page<AbFeekback> page = abFeekbackService.findPage(abFeekback);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("ab:abFeekback:view")
	@RequestMapping(value = "form")
	public String form(AbFeekback abFeekback, Model model) {
		model.addAttribute("abFeekback", abFeekback);
		return "modules/ab/abFeekbackForm";
	}

	/**
	 * 保存服务反馈
	 */
	@RequiresPermissions("ab:abFeekback:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated AbFeekback abFeekback) {
		abFeekback.setCreateTime(new Date());
		abFeekback.setUserName(UserUtils.getUser().getUserName());
		abFeekbackService.save(abFeekback);
		return renderResult(Global.TRUE, text("保存服务反馈成功！"));
	}
	
	/**
	 * 删除服务反馈
	 */
	@RequiresPermissions("ab:abFeekback:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(AbFeekback abFeekback) {
		abFeekbackService.delete(abFeekback);
		return renderResult(Global.TRUE, text("删除服务反馈成功！"));
	}
	
}